package dmxGroupControl.ui;

import java.io.File;
import java.io.FilenameFilter;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;

public class VenueSelectionController
{
    @FXML
    Button btnEdit;
    @FXML
    Button btnRun;
    @FXML
    ListView<String> lstVenues;

    String venuesLocation = "data/venues";
    
    public void initialize()
    {
        File directory = new File(venuesLocation);

        FilenameFilter filter = (dir, name) -> (name.endsWith(".xml"));
		
        File[] files = directory.listFiles(filter);
        for(File file : files)
        {
            lstVenues.getItems().add(file.getName());
        }
        
        btnEdit.setOnAction(event -> Main.GetInstance().SetStage(lstVenues.getSelectionModel().getSelectedItem(), true));
        btnRun.setOnAction(event -> Main.GetInstance().SetStage(lstVenues.getSelectionModel().getSelectedItem(), false));
        
        lstVenues.setOnMouseClicked(
            event ->
            {
                if(event.getClickCount() >= 2)
                {
                    Main.GetInstance().SetStage(lstVenues.getSelectionModel().getSelectedItem(), false);
                }
            }
        );
    }

}
